//
//  MyView.m
//  MMLOOK
//
//  Created by dllo on 15/10/5.
//  Copyright © 2015年 武俊娥. All rights reserved.
//

#import "MyView.h"

@interface MyView ()

@property (nonatomic, retain) UILabel *label;
@property (nonatomic, retain) UIButton *button;

@end

@implementation MyView

- (void)dealloc
{
    [_label release];
    [_button release];
    [super dealloc];
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupViews];
    }
    return self;
}

- (void)setupViews
{
    self.label = [[UILabel alloc] init];
    _label.textColor = [UIColor orangeColor];
    [self addSubview:_label];
    [_label release];
    
    self.button = [[UIButton alloc] init];
    [_button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_button];
    [_button release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.label.frame = CGRectMake(5, 0, 80, self.frame.size.height);
    self.button.frame = CGRectMake(self.frame.size.width - 80, 0, 80, self.frame.size.height);
}

- (void)setSection:(NSInteger)section
{
    if (_section != section) {
        
        _section = section;
    }
    
    if (_section == 1) {
        
        _label.text = @"点点乐";
        [_button setTitle:@"更多分享" forState:UIControlStateNormal];
    } else if (_section == 2) {
        
        _label.text = @"每日惊喜";
        [_button setTitle:@"更多分类" forState:UIControlStateNormal];
    }
}

#pragma mark 更多button的点击方法
- (void)buttonAction:(id)sender
{
    if ([_button.titleLabel.text isEqualToString:@"更多分享"]) {
        
        [self.delegate buttonipAction];
    } else if ([_button.titleLabel.text isEqualToString:@"更多分类"]) {
        
        [self.delegate buttondownAction];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
